<?php
/**
 * @package Autogenerator for Joomla!
 * @version 3.0.0
 * @author Truong Cong Duc <truongcongduc4@gmail.com>
 * @link autogenerator.blogspot.com
 * @copyright (c) 2013, Truong Cong Duc
 * @license GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

JHtml::_('bootstrap.tooltip');
JHtml::_('behavior.multiselect');
JHtml::_('dropdown.init');
JHtml::_('formbehavior.chosen', 'select');

$user = JFactory::getUser();
$userId = $user->get('id');
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));
?>
<link rel="stylesheet" href="<?php echo JUri::root() . AUTOGENERATOR_URL_CSS . 'autogenerator.css'; ?>" type="text/css">
<script src="<?php echo JUri::root() . AUTOGENERATOR_URL_JS . 'autogenerator.js'; ?>" type="text/javascript"></script>

<script type="text/javascript">
    jQuery(document).ready(function() {
        Autogenerator.Edit_Inline.init();
    });
    
	Joomla.orderTable = function() {
		table = document.getElementById("sortTable");
		direction = document.getElementById("directionTable");
		order = table.options[table.selectedIndex].value;
		if (order != '<?php echo $listOrder; ?>') {
			dirn = 'asc';
		} else {
			dirn = direction.options[direction.selectedIndex].value;
		}
		Joomla.tableOrdering(order, dirn, '');
	}
</script>
<form action="<?php echo JRoute::_('index.php?option=com_autogenerator&view=xml_elements&iXmlTypeId=' . $this->iXmlTypeId); ?>" method="post" name="adminForm" id="adminForm">
    <?php if (!empty($this->sidebar)): ?>
        <div id="j-sidebar-container" class="span2">
            <?php echo $this->sidebar; ?>
        </div>

        <div id="j-main-container" class="span10">
    <?php else : ?>
        <div id="j-main-container">
    <?php endif; ?>
            <div id="filter-bar" class="btn-toolbar">
                <div class="filter-search btn-group pull-left">
                    <label for="filter_search" class="element-invisible"><?php echo JText::_('COM_AUTOGENERATOR_XML_ELEMENTS_FILTER_SEARCH_DESC'); ?></label>
                    <input type="text" name="filter_search" placeholder="<?php echo JText::_('COM_AUTOGENERATOR_XML_ELEMENTS_FILTER_SEARCH_DESC'); ?>" id="filter_search" value="<?php echo $this->escape($this->state->get('filter.search')); ?>" title="<?php echo JText::_('COM_AUTOGENERATOR_XML_ELEMENTS_FILTER_SEARCH_DESC'); ?>" />
                </div>
                <div class="btn-group pull-left hidden-phone">
                    <button class="btn tip hasTooltip" type="submit" title="<?php echo JText::_('JSEARCH_FILTER_SUBMIT'); ?>"><i class="icon-search"></i></button>
                    <button class="btn tip hasTooltip" type="button" onclick="document.id('filter_search').value='';this.form.submit();" title="<?php echo JText::_('JSEARCH_FILTER_CLEAR'); ?>"><i class="icon-remove"></i></button>
                </div>
                <div class="btn-group pull-right hidden-phone">
                    <label for="limit" class="element-invisible"><?php echo JText::_('JFIELD_PLG_SEARCH_SEARCHLIMIT_DESC'); ?></label>
                    <?php echo $this->pagination->getLimitBox(); ?>
                </div>
                <div class="btn-group pull-right hidden-phone">
                    <label for="directionTable" class="element-invisible"><?php echo JText::_('JFIELD_ORDERING_DESC'); ?></label>
                    <select name="directionTable" id="directionTable" class="input-medium" onchange="Joomla.orderTable()">
                        <option value=""><?php echo JText::_('JFIELD_ORDERING_DESC'); ?></option>
                        <option value="asc" <?php if ($listDirn == 'asc')
                        echo 'selected="selected"'; ?>><?php echo JText::_('JGLOBAL_ORDER_ASCENDING'); ?></option>
                        <option value="desc" <?php if ($listDirn == 'desc')
                                    echo 'selected="selected"'; ?>><?php echo JText::_('JGLOBAL_ORDER_DESCENDING'); ?></option>
                    </select>
                </div>
                <div class="btn-group pull-right">
                    <label for="sortTable" class="element-invisible"><?php echo JText::_('JGLOBAL_SORT_BY'); ?></label>
                    <select name="sortTable" id="sortTable" class="input-medium" onchange="Joomla.orderTable()">
                        <option value=""><?php echo JText::_('JGLOBAL_SORT_BY'); ?></option>
                        <?php echo JHtml::_('select.options', $this->getSortFields(), 'value', 'text', $listOrder); ?>
                    </select>
                </div>
            </div>
            <div class="clearfix"> </div>

            <table class="table table-striped" id="componentsList">
                <thead>
                    <tr>
                        <th width="1%" class="hidden-phone">
                            <input type="checkbox" name="checkall-toggle" value="" title="<?php echo JText::_('JGLOBAL_CHECK_ALL'); ?>" onclick="Joomla.checkAll(this)" />
                        </th>
                        <!-- START LIST OF HEADER -->
                        <th>
                            <?php echo JHtml::_('grid.sort', 'COM_AUTOGENERATOR_XML_ELEMENTS_HEADER_XML_TYPE_TITLE', 'axt.title', $listDirn, $listOrder); ?>
                        </th>
                        <th width="20%" >
                            <?php echo JHtml::_('grid.sort', 'COM_AUTOGENERATOR_XML_ELEMENTS_HEADER_XML_ATTRIBUTE_TITLE', 'axa.title', $listDirn, $listOrder); ?>
                        </th>
                        <th width="25%" class="nowrap hidden-phone">
                            <?php echo JHtml::_('grid.sort', 'COM_AUTOGENERATOR_XML_ELEMENTS_HEADER_XML_ATTRIBUTE_DEFAULT', 'axa.default', $listDirn, $listOrder); ?>
                        </th>
                        <th width="35%">
                            <?php echo JHtml::_('grid.sort', 'COM_AUTOGENERATOR_XML_ELEMENTS_HEADER_XML_TYPE_CUSTOM', 'axe.custom', $listDirn, $listOrder); ?>
                        </th>
                        <!-- END LIST OF HEADER -->
                        <th width="1%" class="nowrap hidden-phone">
                            <?php echo JHtml::_('grid.sort', 'COM_AUTOGENERATOR_XML_ELEMENTS_HEADER_ID', 'axe.id', $listDirn, $listOrder); ?>
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <?php if ($this->items !== false) : ?>
                        <?php foreach ($this->items as $i => $item) : ?>
                            <tr class="row<?php echo $i % 2; ?>">
                                <td class="center hidden-phone">
                                    <?php echo JHtml::_('grid.id', $i, $item->id); ?>
                                </td>
                                <td class="small hidden-phone">
                                    <?php echo $this->escape($item->xml_type_title); ?>
                                </td>

                                <td class="nowrap has-context">
                                    <?php echo $this->escape($item->xml_attribute_title); ?>
                                </td>
                                <td class="small hidden-phone">
                                    <?php echo $this->escape($item->xml_attribute_default); ?>
                                </td>
                                <td class="small hidden-phone autogenerator-edit-inline-area">
                                    <span class="autogenerator-edit-inline" title="<?php echo JText::_('COM_AUTOGENERATOR_XML_ELEMENTS_XML_TYPE_CUSTOM_CLICK_TO_EDIT_INLINE'); ?>"><?php echo $this->escape($item->custom); ?></span>
                                    
                                    <span class="autogenerator-holder" style="display: none;">
                                        <input type="text" class="autogenerator-custom" name="holder[<?php echo (int) $item->id; ?>]" value="" />

                                        <input class="autogenerator-id" type="hidden" name="holder[id]" value="<?php echo (int) $item->id; ?>" />
                                        &nbsp;&nbsp;
                                        <a href="#" class="autogenerator-save">Save</a>
                                        &nbsp;&nbsp;
                                        <a href="#" class="autogenerator-cancel">Cancel</a>
                                    </span>
                                </td>
                                <td class="center hidden-phone">
                                    <?php echo (int) $item->id; ?>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </tbody>
            </table>
            <?php echo $this->pagination->getListFooter(); ?>
            <input type="hidden" name="task" value="" />
            <input type="hidden" name="boxchecked" value="0" />
            <input type="hidden" name="filter_order" value="<?php echo $listOrder; ?>" />
            <input type="hidden" name="filter_order_Dir" value="<?php echo $listDirn; ?>" />
            <?php echo JHtml::_('form.token'); ?>
            <a href="<?php echo JRoute::_('index.php?option=com_autogenerator&task=xml_element.editInline'); ?>" style="display: none;" class="autogenerator-link">&nbsp;</a>
    </div>
</form>
